﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="zh">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312"/>
    <title>欢迎</title>
    <meta http-equiv='content-type' content='text/html;charset=utf-8'/>
    <script type='text/javascript' src='assets/js/jquery-1.8.2.min.js'></script>
    <script type='text/javascript'>
        $(document).ready(function () {
            var existEmail = false;

            if(location.search !== undefined){
                //获取Location对象的search属性值
                var searchStr = location.search;
                alert("searchStr: " + searchStr);
                if (searchStr != null && searchStr !== "") {
                    //由于searchStr属性值包括“?”，所以除去该字符
                    searchStr = searchStr.substr(1);

                    //将searchStr字符串分割成数组，数组中的每一个元素为一个参数和参数值
                    var searchs = searchStr.split("&amp;");

                    //获得第一个参数和值
                    var email = searchs[0].split("=");
                    if (email[0] === "email" && email[1] != null && email[1] !== "") {
                        existEmail = true;
                        const welcomeText = "欢迎：" + email[1];
                        $("#emailValue").html(welcomeText);
                    }
                }
            }

            if(!existEmail){
                // 从cookie里取
                // 想要获取的cook键值
                const cookie_name = "sessionId";

                // 调用
                const cookie_value = getCookie(cookie_name);

                function getCookie(cookie_name) {
                    const allcookies = document.cookie;
                    alert(allcookies);

                    //索引长度，开始索引的位置
                    var cookie_pos = allcookies.indexOf(cookie_name);
                    // 如果找到了索引，就代表cookie存在,否则不存在
                    if (cookie_pos !== -1) {
                        // 把cookie_pos放在值的开始，只要给值加1即可
                        //计算取cookie值得开始索引，加的1为“=”
                        cookie_pos = cookie_pos + cookie_name.length + 1;
                        //计算取cookie值得结束索引
                        var cookie_end = allcookies.indexOf(";", cookie_pos);

                        if (cookie_end == -1) {
                            cookie_end = allcookies.length;

                        }
                        //得到想要的cookie的值
                        var value = unescape(allcookies.substring(cookie_pos, cookie_end));
                    }
                    return value;
                }

                if (cookie_value != null && cookie_value !== "") {
                    // 验证cookie，并拿到email
                    $.ajax({
                        type: 'get',
                        async: false,
                        url: '/api/user/info/' + cookie_value,
                        success: function (result) {
                            if (result != null && result !== "") {
                                existEmail = true;
                                const welcomeText = "欢迎：" + result;
                                $("#emailValue").html(welcomeText);
                            } else {
                                // 返回登录界面
                                window.location.href = 'login.html';
                            }
                        }
                    });
                }
            }
            if (!existEmail) window.location.href = 'login.html';
        });

    </script>
</head>

<body>
<table border=0>
    <tr>
        <th width=200 height=30></th>
        <th><img src="images/welcome.jpg"></th>
    </tr>
</table>

<table>
    <h2 id="emailValue"></h2>
    <tr>
        <th bgcolor='f9f8ed' height=200 width=2000><p>📧联系邮箱：xxxx@qq.com</p>
            <p>联系地址：XXXXX</p>
            <p>📞联系电话：XXXXX</p></th>
    </tr>
</table>
</body>
</body>
</html>
